package JDBC.Day09_Druid.Demo2;

import JDBC.Day09_Druid.utils.JDBCUtils;
import jdk.nashorn.internal.scripts.JD;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *  使用新的工具类 给testdata数据库中account表添加一条记录
 */
public class InsertDemo {
    public static void main(String[] args) {

        Connection conn = null;
        PreparedStatement pstmt = null;

        try {
            //1. 获取连接
            conn = JDBCUtils.getConnection();
            //2. 定义预编译的sql语句
            pstmt = conn.prepareStatement("INSERT INTO account VALUE (null, ?, ?)");
            //  一定要记得给?号赋值！！！
            pstmt.setString(1, "王五");
            pstmt.setDouble(2, 4000);
            //3. 执行sql
            int count = pstmt.executeUpdate();
            System.out.println(count);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //4. 释放资源
            JDBCUtils.close(pstmt, conn);
        }
    }
}
